﻿"""测试单选框"""
import tkinter as tk
from tkinter import messagebox
from PIL import Image, ImageTk


class Application(tk.Frame):  # Application是应用的含义，需要继承Frame的初始化
    """一个经典的GUI程序的类的写法"""

    def __init__(self, master=None):  # 要传递master
        super().__init__(master)
        self.master = master
        self.pack()  # 通过布局管理显示
        self.create_widget()  # 调用类函数进行初始化小部件

    def create_widget(self):  # Widget是小部件的含义
        self.sex = tk.StringVar();
        self.sex.set('F')

        self.choose_man = tk.Radiobutton(self.master,
                                         text='男性',
                                         variable=self.sex,
                                         value='M')
        self.choose_woman = tk.Radiobutton(self.master,
                                           text='女性',
                                           variable=self.sex,
                                           value='F')
        self.choose_man.pack(side='left')
        self.choose_woman.pack(side='left')
        tk.Button(self.master, text='确定', command=self.confirm).pack(side='left')


    def confirm(self):
        messagebox.showinfo('测试','选择的性别:'+self.sex.get())





def main():
    root = tk.Tk()
    root.geometry("800x500+200+300")
    root.title("测试label标签")
    app = Application(master=root)
    root.mainloop()


if __name__ == '__main__':
    main()
